package terra;

import java.sql.SQLException;

import terra.awt.Frame;
import terra.database.DatabaseFactory;
import terra.database.SqlUtils;
import terra.managers.CraftManager;
import terra.managers.DayNightManager;
import terra.managers.DefManager;
import terra.managers.ItemManager;
import terra.managers.MapManager;
import terra.managers.ThreadPoolManager;
import terra.managers.WeatherManager;
import terra.model.World;
import terra.network.PlayerHandler;
import terra.util.DeadLockDetector;

public class Loader {

	/**
	 * @param args
	 * @throws SQLException
	 */
	static Thread t = new Thread(new Shutdown());
	public static void main(String[] args) throws SQLException {
		Runtime.getRuntime().addShutdownHook(t);
		Config.loadConfig();
		DatabaseFactory.getInstance();
		BootStrap.load(BootStrap.SERVER_MODE, PlayerHandler.class);
		World.getInstance();
		Frame frame = new Frame();
		frame.setVisible(true);
		ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(frame, 1000,
				1000);
		DefManager.init();
		SqlUtils.setAllCharacterOffline();
		CraftManager.getInstance();
		ItemManager.getInstance();
		WeatherManager.getInstance();
		MapManager.getInstance();
		DayNightManager.getInstance();
		new DeadLockDetector().start();
		ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(
				new Runnable() {
					@Override
					public void run() {
						System.gc();
					}
				}, 30000, 10000);
	}

}
